package webserver;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;

public class Processor extends Thread {

	Socket client;
public Processor(Socket s){
	client = s;
}
@Override
public void run() {
	try {
		InputStream is = client.getInputStream();
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		String[] infos = br.readLine().split(" ");
		String path = "F:\\worke\\workspace\\jeecg\\WebContent" + infos[1];
		File file = new File(path);
		FileInputStream fis = new FileInputStream(file);
		InputStreamReader isR = new InputStreamReader(fis);
        BufferedReader fbr = new BufferedReader(isR);
        StringBuffer sb = new StringBuffer();
        String lineTxt = "";
        while(null != (lineTxt = fbr.readLine())){
        	sb.append(lineTxt);
        }
        fbr.close();
        isR.close();
        fis.close();
		OutputStream os = client.getOutputStream();
		PrintStream ps = new PrintStream(os);
		ps.println("HTTP/1.0 200 OK");
		ps.println("Content_Type:text/html");
		int len = (int) file.length();
		ps.println("Content_Length:"+len);
		ps.println();
		ps.println(sb.toString());
		ps.flush();
		client.close();
	
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}



}
